const service = require('../../../utils/service.js');
const api = require('../../../utils/util.js');
Page({
    data: {
        page: 1,
        historyList: [],
        hasMoreData: true
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.init();
    },
    init: function() {
      	this.getList();
    },
    // 获取提现列表
    getList: function() {
        let self = this;
        api.ajax(service.url('getWithdrawList'), {
            page: self.data.page
       	},function(res) {
       		console.log(JSON.stringify(res));
            if(res.code == 0) {
                if(res.data.length > 0) {
                    res.data.forEach(function(item, index) {
                        self.data.historyList.push(item);
                    });
                    self.setData({
                    	historyList: self.data.historyList,
                    	hasMoreData: true
                    });
                } else {
                    self.setData({
                    	hasMoreData: false
                    });
                }
            } else {
                api.toast(res.message);
            }
        });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        let page = this.data.page += 1;
        if(this.data.hasMoreData) {
            this.setData({
                page: page
            })
            this.init()
        } else {
            api.toast('没有更多数据了')
        }
    }
})